import apiClient from '@/apis/axios.js';



export class favoriteApi {

    // 添加视频到收藏夹
    static async addVideoFavorite(fvid, category) {
        try {
            const response = await apiClient.post('/videoFavorite/add', {
                fvid,
                category,
            });
            return response;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    // 从收藏夹删除视频
    static async deleteVideoFavorite(fvid, category) {
        try {
            const response = await apiClient.post('/videoFavorite/delete', {
                fvid,
                category,
            });
            return response;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    // 检查视频是否在收藏夹中
    static async checkVideoFavorite(fvid) {
        try {
            const response = await apiClient.post(`/videoFavorite/check?fvid=${fvid}`);
            return response.data;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    // 获取某个视频的收藏数量
    static async getVideoFavoriteNum(fvid) {
        try {
            const response = await apiClient.post(`/videoFavorite/num?fvid=${fvid}`);
            return response.data;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    // 根据分类获取收藏的视频
    static async getFavoritesByCategory(category) {
        try {
            const response = await apiClient.post(`/videoFavorite/category/${category}`);
            return response.data;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    // 获取收藏夹中的所有分类
    static async getCategoryList(userId) {
        try {
            const response = await apiClient.post('/videoFavorite/categoryList', {
                user_id: userId,
            });
            return response.data;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    // 添加新分类
    static async addCategory(category) {
        try {
            const response = await apiClient.post('/videoFavorite/add_category', {
                category,
            });
            return response;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    // 删除分类
    static async deleteCategory(category) {
        try {
            const response = await apiClient.post('/videoFavorite/delete_category', {
                category,
            });
            return response;
        } catch (error) {
            throw new Error(error.message);
        }
    }

    // 获取当前用户的收藏夹视频
    static async getFavoriteVideos(user_id,category) {
        try {
            const response = await apiClient.post('/videoFavorite/category_show_able', {
                user_id,
                category,
            });
            return response;
        } catch (error) {
            throw new Error(error.message);
        }
    }
}
